package de.uni.muenster.mmm.AndroidCieLab;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import de.uni.muenster.mmm.AndroidCieLab.calculation.RGBtoCieLab;
import de.uni.muenster.mmm.AndroidCieLab.data.IMG;
import de.uni.muenster.mmm.AndroidCieLab.threads.InterpretPixel;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

public class Cam extends Activity{
	private static final int CAMERA_PIC_REQUEST = 1337;
	private ImageView imageViewPic;
	private TextView textView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		imageViewPic = new ImageView(this);
		textView = new TextView(this);
		
		Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
		startActivityForResult(intent, this.CAMERA_PIC_REQUEST);
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		
		// hier wird geguckt, ob der requestCode gleich dem CAMERA_PIC_REQUEST ist
		if(requestCode == CAMERA_PIC_REQUEST && data != null){
			
			// die gespeicherte Bitmap wird aus den Daten extrahiert
			Bitmap bitmap = (Bitmap) data.getExtras().get("data");
			
//			imageViewPic.setImageBitmap(bitmap);
			long start = System.currentTimeMillis();
			
			//convert rgb to cieLab
			IMG img = new IMG();
			
			ExecutorService executorService = Executors.newFixedThreadPool(2);
			executorService.execute(new InterpretPixel(img, bitmap, null));
			executorService.shutdown();
			
			while(!executorService.isTerminated() ){
				
			}
			
			long end = System.currentTimeMillis();
			double diff = ((double)(end - start)) / 1000;
			Log.v("wichtig", "vergangene Zeit: " + diff);
			
			
			textView.setText("5: " + img.five + "\n10: " + img.ten + "\n20: " + img.twenty + "\n50: " + img.fifty + "\n100: " + img.hundred);
			setContentView(textView);
		}
	}

}
